package com.chunguang.study.controller;

import java.util.Date;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.chunguang.study.bean.User;

@RestController
@RequestMapping(value="/index")
public class TestController {
	
	private static final Logger logger = LoggerFactory.getLogger(TestController.class);
	@RequestMapping
	public String index() {
		logger.info("hello info");
		logger.warn("warn info");
		logger.error("error info");
		return "hello world";
		
	}

	// @RequestParam 简单类型的绑定，可以出来get和post
	@RequestMapping(value = "/get")
	public HashMap<String, Object> get(@RequestParam String name) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("title", "hello world");
		map.put("name", name);
		return map;
	}
	
	// @PathVariable 获得请求url中的动态参数
		@RequestMapping(value = "/get/{id}/{name}")
		public User getUser(@PathVariable int id, @PathVariable String name) {
			User user = new User();
			user.setId(id);
			user.setName(name);
			user.setDate(new Date());
			
			return user;
		}
}
